from Common import sql_content


class _Analysis(object):
    def __init__(self):
        self.sql_content = sql_content.sql_content()

    #连接Policy数据库
    def analysis_sql(self,min,max):
        data_all = []
        data_one = {}
        con = self.sql_content.conten()
        sql_policy = "select * from data_51job_she WHERE %d <= Data_Id and Data_Id<= %d"%(min,max)
        cursor = con.cursor()
        try:
            cursor.execute(sql_policy)
            rs = cursor.fetchall()
            #print(rs)
            for row in rs:
                row_list = list(row)
                if len(row_list[1]) > 10:
                    row_list[1] = row_list[1][:10] + '...'
                if len(row_list[9]) > 13:
                    row_list[9] = row_list[1][:13] + '...'

                data_all.append(row_list)
                #print(data_all)
        except Exception as e:
            print(e)
            con.rollback()
        cursor.close()
        con.close()

        return data_all

    # 连接analysis数据库
    def analysis_sql_id(self,id):
        list_data = []
        con = self.sql_content.conten()
        sql_analysis = "select * from data_51job_she WHERE Data_Id = %d" % (id)
        cursor = con.cursor()
        try:
            cursor.execute(sql_analysis)
            rs = cursor.fetchone()
            for row in rs:
                list_data = list(rs)
                if list_data[13] == "":
                    list_data[13] = None
                else:
                    list_data[13] = list_data[13].split('$')
                    del list_data[13][0]
                    del list_data[13][-1]
                if list_data[2] != None:
                    list_data[2] = list_data[2].split('$')
                    del list_data[2][0]
                    del list_data[2][-1]
            print(list_data)
        except Exception as e:
            print(e)
            con.rollback()
        cursor.close()
        con.close()

        return list_data
#测试口
if __name__ == "__main__":
    _Analysis().analysis_sql(1,10)